<!--
* description: 支给件采购单
-->
<template>
  <section class="editCarBrand">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      title="支给件采购单"
      :append-to-body="true"
      :visible.sync="showDialog"
      width="1000px"
      @close="close"
    >
      <dialogHeader slot="title" title="支给件采购单" :styleType="$store.state.app.dialogType"></dialogHeader>
      <div class="filter-container filter-params">
        <el-row :gutter="26">
          <el-table
            :data="tableData"
            style="width: 100%"
            height="400"
            border
            v-loading="listLoading"
          >
            <el-table-column label="序号" width="60" align="center">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column label="采购单号" prop="PURCHASE_CODE" width="120" align="center"></el-table-column>
            <el-table-column label="采购单行号" prop="PURCHASE_LINE_CODE" width="120" align="center"></el-table-column>
            <el-table-column label="备件编号" prop="PART_NO" width="120" align="center"></el-table-column>
            <el-table-column label="备件名称" prop="PART_NAME" width="120" align="center"></el-table-column>
            <el-table-column label="采购数量" prop="PURCHASE_QTY" width="120" align="center"></el-table-column>
            <el-table-column label="发货数量" prop="ARRIVAL_QTY" width="120" align="center"></el-table-column>
            <el-table-column label="发货状态" prop="SHIPMENTS_STATUS_NAME" width="120" align="center"></el-table-column>
            <el-table-column label="供应商编号" prop="SUPPLIER_CODE" width="120" align="center"></el-table-column>
            <el-table-column label="供应商简称" prop="PARTNER_SHORT_NAME" width="120" align="center"></el-table-column>
            <el-table-column label="采购类型" prop="PURCHASE_TYPE_NAME" width="120" align="center"></el-table-column>
            <el-table-column label="到货仓库" prop="WAREHOUSE_NAME" width="120" align="center"></el-table-column>
            <el-table-column label="到货要求时间" prop="RA_TIME_NEW" width="120" align="center"></el-table-column>
            <el-table-column label="审核状态" prop="AUDIT_STATUS_NAME" width="120" align="center"></el-table-column>
            <el-table-column label="审核意见" prop="REMARK" width="120" align="center"></el-table-column>
            <el-table-column label="预计交货时间" prop="DELIVERY_TIME_NEW" width="120" align="center"></el-table-column>
          </el-table>
          <el-pagination
            ref="oneTable.pageArea"
            background
            :page-sizes="this.$config.pageSizeArray"
            :page-size="this.$config.defaultPageSize"
            prev-text="上一页"
            next-text="下一页"
            layout="prev, pager, next, jumper, sizes, ->, total"
            :total="pageTotal"
            :current-page.sync="listQuery.pageIndex"
            :pager-count="7"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer"></div>
    </el-dialog>
  </section>
</template>
<script>
import request from "@/utils/request";
export default {
  components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  props: {
    isShow: { type: Boolean, default: false },
    rowData: { type: Object, default: {} }
  },
  data() {
    return {
      // 查询条件
      listQuery: {
        pageIndex: 1,
        pageSize: this.$config.defaultPageSize
      },
      pageTotal: 0,
      // 显示加载中
      listLoading: false,
      // 是否显示
      showDialog: this.isShow,
      // 表格数据
      tableData: []
    };
  },
  created() {
    if (this.showDialog) {
      this.queryTable();
    }
  },
  methods: {
    close() {
      this.showDialog = false;
      this.$emit("detailClose");
    },
    // 处理每页显示改变事件
    handleSizeChange(val) {
      this.listQuery.pageSize = val;
      this.queryTable();
    },
    // 当前页记录
    handleCurrentChange(val) {
      this.listQuery.pageIndex = val;
      this.queryTable();
    },
    queryTable() {
      let reqData = JSON.parse(JSON.stringify(this.listQuery));
      reqData.PURCHASE_CODE = this.rowData.PURCHASE_CODE;
      reqData.PART_NO = this.rowData.PART_NO;
      this.listLoading = true;
      request({
        url: "/mp/wm/vl/warehouse/purchase/queryAssemblyPurchase.do",
        method: "post",
        data: reqData
      })
        .then(res => {
          this.listLoading = false;
          if (res.result === "1") {
            if (
              res.listResult &&
              res.listResult.rows &&
              res.listResult.rows.length > 0
            ) {
              this.tableData = res.listResult.rows;
              this.pageTotal = res.listResult.records;
            }
          } else {
            if (res.msg || res.debugMsg) {
              this.$message({
                message: res.debugMsg ? res.debugMsg : res.msg,
                uration: 2000
              });
            }
          }
        })
        .catch(err => {
          console.info(err);
          this.listLoading = false;
        });
    }
  }
};
</script>
